//
//  RechargeRecordVC.m
//  BestLearning
//
//  Created by 星道 on 17/9/13.
//  Copyright © 2017年 apple. All rights reserved.
//

#import "RechargeRecordVC.h"
#import "RechargeRecordCell.h"
#import "RechargeRecordModel.h"

@interface RechargeRecordVC ()<UITableViewDataSource,UITableViewDelegate>
@property (strong, nonatomic) IBOutlet UITableView *tableView;
@property (strong, nonatomic) IBOutlet UILabel *account;
@property (strong, nonatomic) IBOutlet UIActivityIndicatorView *activity;
@property (strong, nonatomic) NSMutableArray *dataArr;
@end

@implementation RechargeRecordVC

- (void)viewDidLoad {

    [super viewDidLoad];

    self.title = @"充值记录";

    [self.tableView registerNib:[UINib nibWithNibName:[RechargeRecordCell description] bundle:nil] forCellReuseIdentifier:@"cell"];

    [self refreshData];

    self.account.text = [AccountTool shareAccountTool].currentAccount.username;
}



#pragma mark - 网络 
- (void)refreshData {

    NSDictionary *params = @{
                             @"action"  :@"rechargeRecord",
                             @"uid"     :[AccountTool shareAccountTool].currentAccount.uid
                
                                 };
    
    [NetManager Get:LLBaseURLs(@"user.do") Auth:YES Params:params Success:^(id Obj) {
        [self.activity stopAnimating];
        if ([Obj[@"code"] isEqualToNumber:@1000]) {
            
            NSArray *arr = Obj[@"t"][@"dataList"];
            [arr enumerateObjectsUsingBlock:^(NSDictionary * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
                [self.dataArr addObject:[RechargeRecordModel HNObjectValuesForKey:obj]];
            }];
            
            [self.tableView reloadSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:(UITableViewRowAnimationAutomatic)];
        } else {
            
            [MBProgressHUD showError:Obj[@"msg"]];
        }
    } Fail:^(NSError *Error) {
        [self.activity stopAnimating];
        [MBProgressHUD showError:@"链接超时"];
    }];
}


#pragma mark - tabelView delegate
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {

    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return self.dataArr.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    RechargeRecordModel *model = self.dataArr[indexPath.row];
    RechargeRecordCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    cell.model = model;
    return cell;
}

#pragma mark - getter
- (NSMutableArray *)dataArr {

    if (!_dataArr) {

        _dataArr = [NSMutableArray array];
    }
    return _dataArr;
}
@end
